﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Checkers.Common
{
    /// <summary>
    /// This class represents a move on the game
    /// </summary>
    public class GameMove
    {
        // Data members
        private Location m_SourceCell;
        private Location m_DestCell;

        // Properties

        /// <summary>
        /// Getter for m_SourceCell
        /// </summary>
        public Location SourceCellLoc
        {
            get
            {
                return m_SourceCell;
            }
        }

        /// <summary>
        /// Getter for m_DestCell 
        /// </summary>
        public Location DestCellLocation
        {
            get
            {
                return m_DestCell;
            }
        }

        // Ctor 
        public GameMove(Location i_SourceLocCell, Location i_DestLocCell)
        {
            m_SourceCell = i_SourceLocCell;
            m_DestCell = i_DestLocCell;
        }

        // Public methods 
        
        /// <summary>
        /// Check the type of the move
        /// </summary>
        /// <returns>The type of the move : Non, Jump or RegularMove</returns>
        public eMoveType ChekMoveType()
        {
            // Varibles
            int sourceRow = m_SourceCell.Row;
            int destRow = m_DestCell.Row;
            eMoveType moveType = eMoveType.Non;

            // Check if the move is a jump or a regular move
            if (sourceRow - destRow == 2 || sourceRow - destRow == -2)
            {
                moveType = eMoveType.Jump;
            }
            else if (sourceRow - destRow == 1 || sourceRow - destRow == -1)
            {
                moveType = eMoveType.RegularMove;
            }

            return moveType;
        }

        /// <summary>
        /// Check if the move create a king 
        /// </summary>
        /// <returns>True if it create a king, false if not</returns>
        public bool isDestMakeKing(GameBoard i_GameBoard)
        {
            // Varibles
            int destRow = m_DestCell.Row;
            bool v_IsDEstMakeKing = true;
            
            // Check if the move create a king 
            if (!(destRow == 0 || destRow == i_GameBoard.Height))
            {
                v_IsDEstMakeKing = false;
            }

            return v_IsDEstMakeKing;
        }

        /// <summary>
        /// Converts a GameMove object to a string
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0} to {1}", m_SourceCell.ToString(), m_DestCell.ToString());
        }
    }   
}
